package com.ewzj.bigdata.mvp.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.extensions.initcolor
import com.ewzj.bigdata.di.component.DaggerVideoFragmentComponent
import com.ewzj.bigdata.di.module.VideoFragmentModule
import com.ewzj.bigdata.mvp.contract.VideoFragmentContract
import com.ewzj.bigdata.mvp.presenter.VideoFragmentPresenter
import com.gyf.barlibrary.ImmersionBar
import com.jess.arms.base.BaseFragment
import com.jess.arms.di.component.AppComponent
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import kotlinx.android.synthetic.main.fragment_video.*

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class VideoFragment:BaseFragment<VideoFragmentPresenter>(),VideoFragmentContract.View{
    companion object{
        fun newInstance():VideoFragment{
            val fragment=VideoFragment();
            val args=Bundle();
            fragment.arguments=args;
            return fragment
        }
    }
    override fun setupFragmentComponent(appComponent: AppComponent?) {
        DaggerVideoFragmentComponent.builder().appComponent(appComponent)
                .videoFragmentModule(VideoFragmentModule(this))
                .build().inject(this)
    }

    override fun setData(data: Any?) {

    }

    override fun initView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view=inflater!!.inflate(R.layout.fragment_video,null)
        return view
    }

    override fun initData(savedInstanceState: Bundle?) {
        swipeRefreshLayout.initcolor()
        swipeRefreshLayout.setOnRefreshListener { mPresenter.FirstVidedata() }
        rvvideos.layoutManager=LinearLayoutManager(activity)
        rvvideos.addItemDecoration(HorizontalDividerItemDecoration.Builder(activity).size(2).colorResId(R.color.colorf2)
                .build())
        rvvideos.setHasFixedSize(true)
        if (rvvideos.adapter!=null)return
        mPresenter.initAdapter(rvvideos)
        mPresenter.FirstVidedata()
    }

    override fun showLoading() {
        swipeRefreshLayout.isRefreshing=true
    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {
        swipeRefreshLayout.isRefreshing=false
    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }
    fun setStatusBar(mImmersionBar:ImmersionBar){
        mImmersionBar.navigationBarEnable(false).statusBarDarkFont(true, 0.2f).fitsSystemWindows(true).init()
    }
}